package com.xy.bizportdemo.conversation;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;

import com.xy.bizportdemo.R;
import com.xy.bizportdemo.database.entity.ConversationItem;

/**
 * 企业信息列表的Adapter
 * Created by XIAOYUAN on 2016/11/24.
 */
public class ConversationListAdapter extends CursorAdapter {
    private final LayoutInflater mFactory;
    public boolean SCROLL_STATE_FLING = false;

    @SuppressWarnings("deprecation")
    public ConversationListAdapter(Context context, Cursor cursor) {
        super(context, cursor);
        this.mFactory = LayoutInflater.from(context);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent){
        View view = mFactory.inflate(R.layout.conversation_list_item, parent, false);
        ConversationListItem conversationListItem = new ConversationListItem(view);
        view.setTag(conversationListItem);
        return view;
    }

    @Override
    public void bindView(View convertView, Context context, Cursor cursor){
        ConversationListItem conversationListItem = (ConversationListItem) convertView.getTag();
        conversationListItem.setmIsScrolling(SCROLL_STATE_FLING);
        conversationListItem.bind(context, new ConversationItem(cursor));
    }
}
